package com.hd.trans.framework.languages;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.hd.trans.R;
import com.hd.trans.framework.dialog.ShareDialogModule;

public class ShareResultAdapter extends RecyclerView.Adapter<ShareResultAdapter.ViewHolder> {

    private boolean isNation;
    private ShareDialogModule data;
    private Dialog dialog;

    public ShareResultAdapter(Dialog dialog, ShareDialogModule data,boolean isNation) {
        this.data = data;
        this.dialog = dialog;
        this.isNation = isNation;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(isNation?R.layout.share_item_layout2:R.layout.share_item_layout, parent, false);
        return new ViewHolder(view);
    }

    @SuppressLint("RecyclerView")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        ShareItemBean mData = data.getList().get(position);
        holder.text.setText(mData.getText());
        holder.icon.setImageResource(mData.getIcon());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != data.getListenner()) {
                    data.getListenner().OnItemClick(dialog, ShareResultAdapter.this, position);
                }
            }
        });
    }


    @Override
    public int getItemCount() {
        if (null == data) return 0;
        return null == data.getList() ? 0 : data.getList().size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView text;
        private final ImageView icon;

        public ViewHolder(@NonNull View view) {
            super(view);
            text = (TextView) view.findViewById(R.id.text);
            icon = (ImageView) view.findViewById(R.id.icon);
        }
    }
}
